<?php

namespace Modules\Car\Http\Controllers;

use App\Helpers\ResponseData;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Car\Entities\CarCategory;

class CarCategoryController extends Controller
{
    use ResponseData;
    public function list(CarCategory $category,Request $request){
        $type = $request->input('type','');
        $size = $request->input('size',10);
        if($type=='all'){
            $data = $category->orderBy('id','desc')->get();
        }else{
            $data = $category->orderBy('id','desc')->paginate($size);
        }

        return $this->success($data);
    }
    public function store(CarCategory $category,Request $request){
        $data = $request->all();
        $category->fill($data);
        $category->save();
        return $this->success('保存成功');
    }
    public function edit(CarCategory $category,Request $request){
        $data = $category->find($request->id);
        return $this->success($data);
    }
    public function update(CarCategory $category,Request $request){
        $data = $category->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(CarCategory $category,Request $request){
        $data = $category->find($request->id);
        $data->delete();
    }
}
